package cn.sms.order.controller;

import cn.sms.order.domain.AdoptOrder;
import cn.sms.order.domain.OrderAddress;
import cn.sms.order.domain.ProductOrder;
import cn.sms.order.service.IAdoptOrderService;
import cn.sms.order.service.IOrderAddressService;
import cn.sms.order.service.IProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/orderAddress")
public class OrderAddressController {
    @Autowired
    private IAdoptOrderService adoptOrderService;
    @Autowired
    private IOrderAddressService orderAddressService;
    @Autowired
    private IProductOrderService productOrderService;

    @PostMapping
    public Map<String,Object> getOrderAddress(@RequestBody ProductOrder productOrder){
        System.out.println(productOrder.getPaySn());
        AdoptOrder adoptOrder1 = adoptOrderService.queryByPaySn(productOrder.getPaySn());
        ProductOrder productOrder1 = null;
        OrderAddress orderAddress1 = null;
        Map map = new HashMap<>();
        if(adoptOrder1 == null){
            productOrder1 = productOrderService.queryByOrderSn(productOrder.getPaySn());
            orderAddress1 = orderAddressService.queryByOrderSn(productOrder1.getOrderSn());
            map.put("orderAddress1", orderAddress1);
            map.put("productOrder1", productOrder1);
            map.put("adoptOrder1", null);
            return map;
        }else {
            orderAddress1 = orderAddressService.queryByOrderSn(adoptOrder1.getOrderSn());
            map.put("adoptOrder1", adoptOrder1);
            map.put("orderAddress1", orderAddress1);
            return map;
        }
    }
}

